package com.cosina.game.tank;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;

public class ImageManager {
	public static Bitmap tankUp, tankDown, tankLeft, tankRight,
						enemyUp, enemyDown, enemyLeft, enemyRight,
						brickWall,damage , heart,pill;
	public static Bitmap[] death = new Bitmap[21];
	public static void init(Context context){
		Resources resources = context.getResources();
		
		tankUp = loadBallView(resources, R.drawable.green_up);
		tankDown = loadBallView(resources, R.drawable.green_down);
		tankLeft = loadBallView(resources, R.drawable.green_left);
		tankRight = loadBallView(resources, R.drawable.green_right);

		enemyUp = loadBallView(resources, R.drawable.red_up);
		enemyDown = loadBallView(resources, R.drawable.red_down);
		enemyLeft = loadBallView(resources, R.drawable.red_left);
		enemyRight = loadBallView(resources, R.drawable.red_right);
		
		brickWall = loadBallView(resources, R.drawable.brickwall);
		damage = loadBallView(resources, R.drawable.damage);
		heart = loadBallView(resources, R.drawable.heart);
		pill = loadBallView(resources, R.drawable.pill,7);
		loadDeath(resources,R.drawable.deathyellow);
	}
	
	private static void loadDeath(Resources resources,int resId){
		Bitmap bitmap = BitmapFactory.decodeResource(resources, resId);
		for(int i=0; i<21;i++){
			death[i] = Bitmap.createBitmap(bitmap, i*32, 0, 32, 32);
		}
	}
	
	 private static Bitmap loadBallView(Resources resources,int resId) {
	        return loadBallView(resources,resId,31);
	    }
	 
	 private static Bitmap loadBallView(Resources resources,int resId, int size) {
		 
			Drawable image = resources.getDrawable(resId);
			Bitmap bitmap = Bitmap.createBitmap(size,size, Bitmap.Config.ARGB_8888);
	        
	        Canvas canvas = new Canvas(bitmap);
	        image.setBounds(0, 0, size,size);
	        image.draw(canvas);
	        return bitmap;
	    }
}
